package base.day16.service;

import base.day16.dao.OtherStudentDao;
import base.day16.dao.StudentDao;
import base.day16.domain.Student;

public class StudentService {
    private OtherStudentDao studentDao=new OtherStudentDao();
    public boolean addStudent(Student stu) {
        //创建studentdao库管
        return studentDao.addStudent(stu);
    }

    public boolean isExists(String id) {
        Student[] stus=studentDao.findAllStudent();
        boolean exists=false;
        for (int i = 0; i < stus.length; i++) {
            Student student=stus[i];
            if (student!=null&&student.getId().equals(id)){
                exists=true;
                break;
            }
        }
        return exists;
    }

    public Student[] findAllStudent() {
        Student[] allstudent=studentDao.findAllStudent();
        boolean flag=false;
        for (int i = 0; i < allstudent.length; i++) {
            Student stu=allstudent[i];
            if (stu!=null){
                flag=true;
                break;
            }
        }
        if (flag){
            return allstudent;
        }
        else {
            return null;
        }
    }

    public void deldteStudentById(String deid) {
        StudentDao.deldteStudentById(deid);
    }

    public void upDateStudent(String upateId, Student newstu) {

        studentDao.studentDao(upateId,newstu);
    }
}
